/**
 * Created by Administrator on 2015/6/8.
 */
define(['jquery','alert','check'],function($,alert,check){
    function login(){

        var html='<div class="userlogin clearfix">'+
                 '<p><label for="user_login">用户名<br>'
            +'<input type="text" size="20" value="" class="input" id="user_login" name="username"></label> </p>'
        +'<p> <label for="user_pass">密码<br>'
        +'<input type="password" size="20" value="" class="input" id="user_pass" name="userpassword"></label> </p>'
        +'<p class="forgetmenot code-img"><img id="code-img" title="点击刷新验证码"  src="/refresh" width="70px" height="30px" /><input type="text" name="code-value" value="" placeholder="请输入4位验证码"></p>'
        +'<p class="submit">'
        +'<input type="submit" value="登录" class="button" id="wp-submit" name="wp-submit">'
        +'</p><p id="js_loginerr" style="color:red;clear:both"></p></div>';
        alert.Box(400,'用户登陆',html,0);
        $('#hy_Opendiv #code-img').click(function(){
            $(this).attr('src','/refresh?v='+Math.random());
        });
        $('[name=wp-submit]').click(function(){
            $.ajax({
                type: "POST",
                url: "/login",
                data: {name:$('#hy_Opendiv [name=username]').val(),password:$('#hy_Opendiv [name=userpassword]').val(),code:$('#hy_Opendiv [name=code-value]').val()},
                dataType:"json",
                success: function(msg){
                    if(msg.success==1){
                         $('#hy_Opendiv_close').click();
                         window.location.reload();
                    }
                    if(msg.success==0){
                         $('#js_loginerr').text('用户密码或验证码错误！');
                    }
                    if(msg.success==2){
                        $('#js_loginerr').text(msg.text);
                    }
                }
            })
        })

    }//会员登陆
    function reg(){
        var html='<div class="userlogin userReg clearfix">'
            +'<form action="/reg" method="post" enctype="multipart/form-data" id="js_checkreg">'
            +'<p><label for="user_login">昵称（*2-6个汉字，必须为中文）<br>'
            +'<input type="text" size="20" value="" class="input" id="user_login" name="userNick"></label> </p>'
            +'<p><label for="user_login">用户名（*3-8位，字母或者数字组合）<br>'
            +'<input type="text" size="20" value="" class="input" id="user_login" name="userName"></label> </p>'
            +'<p> <label for="user_pass">密码（*6-12位，字母或者数字组合）<br>'
            +'<input type="password" size="20" value="" class="input" id="user_pass" name="userPassword"></label> </p>'
        +'<p><label for="user_login">QQ<br>'
        +'<input type="text" size="20" value="" class="input" id="user_login" name="userQQ"></label> </p>'
        +'<p><label for="user_login">性别（*输入男或者女）<br>'
        +'<input type="text" size="20" value="男" class="input" id="user_login" name="userSex"></label> </p>'
        +'<p style="margin-bottom: 15px;"><label for="user_login">头像(*请上传小于1M的图片 像素最佳80*80)<br>'
        +'<input type="file" name="userImg" ></label> </p>'
            +'<p class="forgetmenot code-img"><img id="code-img" src="/refresh?v='+Math.random()+'" width="70px" height="30px" title="点击刷新验证码" /><input type="text" name="codeValue" value="" placeholder="请输入4位验证码"></p>'
            +'<p class="submit">'
            +'<input type="submit" value="注册" class="button" id="wp-submit" name="wp-submit">'
            +'</p></div></form>';
           alert.Box(400,'用户注册',html,0);
        $('#hy_Opendiv #code-img').click(function(){
            $(this).attr('src','/refresh?v='+Math.random());
        });
        $('[name=userNick]').blur(function(){
            CheckForm.check.reg($(this),$(this),'text',3,13);
        });
        $('[name=userName]').blur(function(){
            CheckForm.check.reg($(this),$(this),'numeng',2,9);
        });
        $('[name=userPassword]').blur(function(){
            CheckForm.check.reg($(this),$(this),'numeng',5,13);
        });
        $('[name=userQQ]').blur(function(){
            CheckForm.check.reg($(this),$(this),'Num',3,20);
        });
        $('[name=userSex]').blur(function(){
            CheckForm.check.reg($(this),$(this),'text',1,3);
        });
        $('[name=wp-submit]').click(function(){
           var c=true;
            $('#js_checkreg input').each(function(){
               if($(this).is('.Check_Rfalse')){
                   $(this).focus();
                   c=false;
                   return false;
               }
           });
           if(!c){return false;}
        });

    }//会员注册
    return{
        userLogin:login,
        userReg:reg
    }
});